<?php

namespace App\Http\Controllers\Baidu;

use Illuminate\Http\Request;
use	Exception;

//include_once ('../app/libary/Baidu/Signer.php');
include_once ('../app/libary/Baidu/sms_service_ReportService.php');

use sms_service_ReportService;

use getRealTimeQueryDataRequest;
use getRealTimeDataRequest;


class ReportController
{

    /**
     * @return mixed|string
     * 实时报告-包含多类报告。
     * 请求账户，计划，单元，关键词keywordid，
     * 关键词wordid，创意，地域等7种绩效数据报告，
     * 请求时提供所需数据报告的条件，返回本次请求数据。
     */
    public function getRealTimeData()
    {
        $data['performanceData'] = ['cost','cpc','click','impression','ctr','cpm','conversion','bridgeConversion'];
        $data['startDate'] = date('Y-m-d',time());
        $data['endDate'] =date('Y-m-d',time());
        $data['attributes'] = null;
        $data['statIds'] = null;
        $data['device'] = 0;
//  levelOfDetails      2：账户粒度  3：计划粒度  5：单元粒度  7：创意粒度  11：关键词(keywordid)粒度  12：关键词(keywordid)+创意粒度  6：关键词(wordid)粒度
        $data['levelOfDetails'] = 11;
//  reportType      2：账户 10：计划 11：单元 14：关键词(keywordid)  12：创意 3：地域  9：关键词(wordid)
        $data['reportType'] = 14;

        $data['statRange'] = 11;
//dd($data);
        $RealTimeDataRequest = new GetRealTimeDataRequest();
        $RealTimeDataRequest->setRealTimeRequestType($data);

        $report = new sms_service_ReportService();
        $data = $report->getRealTimeData($RealTimeDataRequest);
//dd($data);
        $data = json_encode($data);
        return $data;


    }

    //搜索词报告
    public function getRealTimeQueryData()
    {
        $data['performanceData'] = ['click','impression','cost','ctr'];
        $data['startDate'] = '2018-01-09';
        $data['endDate'] = '2018-01-10';
        $data['levelOfDetails'] = 12;
        $data['attributes'] = null;
        $data['reportType'] = 6;
        $data['statIds'] = null;
        $data['device'] = 0;
        $data['order'] = true;

        $RealTimeQueryDataRequest = new getRealTimeQueryDataRequest();
        $RealTimeQueryDataRequest->setRealTimeQueryRequestType($data);

        $report = new sms_service_ReportService();
        $data = $report->getRealTimeQueryData($RealTimeQueryDataRequest);

        return json_encode($data);



    }







}


